package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectPlanDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.UpdateNursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @Author: Insight
 * @Description: TODO
 * @Date: 2024/6/2 17:02
 * @Version: 1.0
 */

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getByPage(NursingProjectDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Page<NursingProjectVo> page = nursingProjectMapper.selectByPage(dto);
        PageResponse<NursingProjectVo> of = PageResponse.of(page, NursingProjectVo.class);
        return of;
    }

    @Override
    public void insert(NursingProjectPlanDto dto) {
        NursingProject nursingProject = BeanUtil.copyProperties(dto, NursingProject.class);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.insert(nursingProject);
    }

    @Override
    public NursingProjectVo selectById(Long id) {
        NursingProjectVo vo = nursingProjectMapper.selectById(id);
        return vo;
    }

    @Override
    public void update(UpdateNursingProjectDto dto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(dto,nursingProject);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void delete(Integer id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public void disAble(Long id, Integer status) {
        nursingProjectMapper.disAble(id,status);
    }
}
